<template>
  <div class="region">
    <div class="content">
      <div class="left">地区:</div>
      <ul>
        <li :class="{active:activeFlag==''}">全部</li>
        <li 
        v-for="item in regionArr" 
        :key="item.value"
        @click="changeRegion(item.value)"
        :class="{active:activeFlag===item.value}"
        >{{ item.name }}</li>
      </ul>
    </div>
  </div>
</template>

<script setup lang="ts">
import { reqHospitalLevelAndRegion } from "@/api/home";
import { onMounted, ref } from "vue";
import { HospitalLevelAndRegionResponseData, HospitalLevelAndRegionArr } from '@/api/home/type'
// 定义一个存储地区的数据
let regionArr = ref<HospitalLevelAndRegionArr>([])
// // 定义一个 控制高亮 的响应式数据
let activeFlag = ref<string>('')
onMounted(() => {
  getRegion()
})
// 获取地区数据
const getRegion = async() => {
  let res:HospitalLevelAndRegionResponseData = await reqHospitalLevelAndRegion('Beijin')
  // console.log(res)
  if(res.code== 200) {
    regionArr.value = res.data
  }
}
// 点击地区 小li触发  
const changeRegion = (region: string) => {
  activeFlag.value = region
  // 给父组件传递 region
  $emit('getRegion',region)
}
let $emit = defineEmits(['getRegion'])
</script>

<style scoped lang="scss">
.region {
  color:#7f7f7f;
  margin-top: 20px;
  .content {
    display: flex;
    .left {
      margin-right: 10px;
      width: 48px;
    }
    ul {
      display: flex;
      flex-wrap: wrap;
      li {
        margin-right: 10px;
        margin-bottom: 10px;
        &.active {
          color: #55a6fe;
        }
      }
      li:hover {
        color: #55a6fe;
      }
    }
  }
}
</style>